package com.bistu.xiong.tulingrobotchat.frags.account.media;


import android.app.Dialog;
import android.os.Bundle;
import android.support.design.widget.BottomSheetDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bistu.xiong.common.app.Application;
import com.bistu.xiong.common.widget.GalleryView;
import com.bistu.xiong.factory.eventbus.MessageEvent;
import com.bistu.xiong.tulingrobotchat.R;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 图片选择Fragment
 */
public class GalleryChoosePicsFragment extends BottomSheetDialogFragment{

    private GalleryView mGallery;

    public GalleryChoosePicsFragment() {

    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return super.onCreateDialog(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // 获取我们的GalleryView
        View root = inflater.inflate(R.layout.fragment_gallery, container, false);
        mGallery = (GalleryView)root.findViewById(R.id.galleryView);
        return root;
    }

    @Override
    public void onStart() {
        super.onStart();
        mGallery.setup(getLoaderManager(), null);
    }

    @Override
    public void onDestroy() {
        ArrayList<String> imageList = new ArrayList<>(Arrays.asList(mGallery.getSelectedPath()));
        imageList = (imageList==null?new ArrayList<String>():imageList);
        EventBus.getDefault().post(new MessageEvent(imageList,MessageEvent.GalleryChoosePicsFragment));
        super.onDestroy();
    }


}
